<?php

class InboxPlugin {
    var $ld;
    var $xmlsOb;
    var $bot;
    var $translate;
    var $LangNotice;
    var $XMLtransl;

    function InboxPlugin() {
     $this->ld = new LocalData();
     $bot = new Bot();
    }
    // ==========================================================================
    // ==========================================================================
    // ==========================================================================
    function GetForm()
    {
      global $imagePath;
      $imagePath = substr($_SERVER["PHP_SELF"], 0, strpos($_SERVER["PHP_SELF"], "/"));


      echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
           <html xmlns="http://www.w3.org/1999/xhtml" lang="ru">
           <head>
           <title>Buildings</title>
           <script src="..\..\codebase-php\jquery-1.4.2.min.js"></script>
           <script src="..\..\codebase-php\jquery.json-2.2.min.js"></script>
           <link href="helpers/plugin.css" rel="stylesheet" type="text/css">
           <style>
             #maint{ font-size: 10pt; width: 850px; padding: 0px; }
           </style>
          <script>
          //==============================================================
          window.reload = function(){
             var l=window.location.toString();
             var indx=l.indexOf(\'?\');
             window.location=l.slice(0, indx)+"?action=refresh&tmp="+Math.random();
          }
          //==============================================================
          $(document).ready(
             function()
             {
               window.settings=eval('.json_encode($this->ld->GetPlSettings('inbox')) . ');
               if ((window.settings!==null) && (window.settings!==undefined))
               {
                 $(":checkbox").each(
                    function(){
                      if(window.settings[$(this).attr("id")]==true){
                        $(this).attr("checked", true);
                      }
                      else{
                        $(this).attr("checked", false);
                      }
                    });
                 $(":text").each(
                    function (){
                      var attr=$(this).attr("id");
                      if (window.settings[attr]!==null){
                        $(this).val(window.settings[attr]);
                      }
                      else{
                        $(this).val("0");
                      }
                    });
               }
               //==============================================================
               $("#btn_save").click(function()
               {
                 var req=new Object();
                 $(":checkbox").each(function()
                 {
                   var par=$(this).attr("id");
                   req[par]=$(this).attr("checked");
                   if (($(this).attr("objid")!==null) && ($(this).attr("objid")!==undefined))
                   {
                     req[par+"ID"]=$(this).attr("objid");
                   }
                 });
                 $("input:text").each(function()
                 {
                   req[$(this).attr("id")]=$(this).val();
                 });

                 data=$.toJSON(req);
                 var l=window.location.toString();
                 var indx=l.indexOf(\'?\');
                 var nurl=l.slice(0, indx)+"?action=save&tmp="+Math.random();
                 $.post(nurl, data);
                 return false;
               });
             });
          </script>

          </head>
          <body>';
//==============================================================================

      echo  '<h1>Inbox Plugin 0.4 by Tonycell (12.09.2011)</h1>
            <hr>
            </div>
            <table border="1" cellspacing="1" cellpadding="1" width="100%" bgcolor="#ff0066">
             <tr height="23">
              <td><h3>Actions</h3></td>
             </tr>
            </table>

            <h2>&#187; Gifts</h2>
            <div style="margin-left: 30px">
            <input type="checkbox" id="gifts">Accept Gifts?<br>
            <b>Options</b><br>
            <input type="checkbox" id="giftsNot">Do not accept the same Gift twice in a row (except for Mystery Gifts)<br>
            <br>
			<input type="checkbox" id="ignoregifts">Ignore Gifts?<br>
			</div>
            <br>
			
            <h2>&#187; Help Requests</h2>
            <div style="margin-left: 30px">
            <input type="checkbox" id="help">Send Help requests?<br>
            <b>Options</b><br>
            <input type="checkbox" id="helpNot">Do not send the same Help twice in a row (it helps to prevent Error messages)<br>
            <input type="text" id="helpN" value="0" size="4"> <- amount of Help actions (0=all)
			<br>
			<br>
			<input type="checkbox" id="ignorehelp">Ignore Help requests?<br>
            </div>
            <br>

            <h2>&#187; Neighbor Invitations</h2>
            <div style="margin-left: 30px">
            <input type="checkbox" id="neighbor">Accept Neighbor invitations?<br>
            </div>
            <br>

            <h2>&#187; Crew Invites</h2>
            <div style="margin-left: 30px">
            <input type="checkbox" id="crew">Accept Crew invites?<br>
            </div>
            <br>

            <h2>&#187; Factory Invites</h2>
            <div style="margin-left: 30px">
            <input type="checkbox" id="factory">Accept Factory invites?<br>
            </div>
            <br>

            <h2>&#187; Social Buildings</h2>
            <div style="margin-left: 30px">
            <input type="checkbox" id="vip">Accept VIP requests?<br>
            </div>
            <br>

            <table border="1" cellspacing="1" cellpadding="1" width="100%" bgcolor="#ff0066">
             <tr height="23">
              <td><h3>Requests</h3></td>
             </tr>
           </table>
           <br>
           Pending request list:
           <table class="table66" border="1" cellspacing="1" cellpadding="1" width="auto" bgcolor="#ff0066" style="table-layout=fixed">
            <tr>
             <td>&nbsp;</td>
             <td><b>Id</b></td>
             <td><b>Type</b></td>
             <td><b>Sender</b></td>
             <td><b>Info</b></td>
            </tr>';

           $PendingRequests = $this->ld->GetSelect('SELECT * FROM Inbox order by type_id, type_text');
           //print_r($Objects);
           foreach ($PendingRequests as $request)
		       {
             //0[hash]
             //1[type_id] INTERGER,
             //2[type_text] NVARCHAR(50) NULL,
             //3[sender] INTERGER,
             //4[accept] NVARCHAR(250),
             //5[ignore] NVARCHAR(250),
             //6[picture] NVARCHAR(250),
             //7[material] VARCHAR(80) NULL)

             echo '<tr>';
             if ($request[6]==null)
             { echo '<td></td>'; }
             else
             { echo '<td><img border="0" hspace="0" src="'.$request[6].'" width="25" height="25" /></td>'; } //picture
             echo '<td>'.$request[1].'</td>';
             echo '<td>'.$request[2].'</td>';
             echo '<td>'.$request[3].'</td>';
             echo '<td>'.$request[7].'</td>';
             //echo '<td>'.$request[1].'</td>';
             //echo '<td>'..'</td>';
             echo '</tr>';
           }
      echo '</table>
            <br>
            <hr>
            <div width="100%" align="center">
            <button id="btn_save" style="color:white;background-color:#13a89e;border-width:1px;border-style:solid; ">&nbsp;Save Settings&nbsp;</button>
            </div>
            <hr>';



      echo '<br></body></html>';
    }

}

?>